<template>
	<view class="content padding-30 u-cb-white-bg">
		<view class="mt-80">
			<view class="u-text-align-center fsize-36 mb-40">￥{{form.amount}}</view>
			<u-form 
				:model="form"
				ref="uForm"
				labelWidth="80"
				:errorType="['toast']">
				<u-form-item label="支付密码" prop="password" borderBottom>
					<u-input
						type="password"
						:focus="true"
						placeholder="请输入支付密码"
						v-model="form.password"
						border="none">
					</u-input>
				</u-form-item>
			</u-form>
			<view class="mt-60 u-flex">
				<u-button type="warning" text="取消支付" @click="$u.route({
				url:'/pages/home/index-member',
				type:'redirectTo'
			})" />
				<u-button text="确认支付" type="error" @click="onSubmit" />
			</view>
		</view>
		<u-toast ref="uToast" />
	</view>
</template>

<script>
	export default{
		data(){
			return {
				isShowPayment: false,
				content:'',
				title:'',
				form:{
					password:'',
					amount:0,
					explain:'',
					casher_appid: '',
				},
				rules:{
					password:[
						{
							required: true, 
							message: '请输入密码',
							trigger: ['change','blur'],
						}
					]
				}
			}
		},
		onShow() {
			if(!this.$store.state.hasLogin){
				uni.reLaunch({
					url: '/pages/login/mlog'
				})
			}
		},
		onLoad(option){
			let sce = decodeURIComponent(option.scene)
			let arr = sce.split(':');
			this.form.casher_appid = arr[0]
			this.form.amount = arr[1]
			if(this.form.amount == 0){
				uni.$u.route({
					url:'/packgeA/user/payment2',
					params: {scene:option.scene}, 
					type:'redirectTo',
				})
			}
		},
		onReady() {
			this.$refs.uForm.setRules(this.rules)
		},
		methods:{
			onSubmit(){
				let that = this
				this.$refs.uForm.validate().then(res => {
					that.$reqPost('/SetMemberConsume', that.form).then(res=>{
						that.$refs.uToast.show({
							message: res.Message,
							complete(){
								that.$u.route({
									url: '/pages/home/index-member',
									type: 'redirectTo'
								})
							}
						})
						let info = {
							...uni.getStorageSync('userInfo'),
							FAmount:res.Data[0].mSpareJe,
							FIntegral:res.Data[0].mSpareFs
						}
						uni.setStorageSync('userInfo',info)
					})
				})
			}
		}
	}
</script>

<style scoped lang="scss">
	.content{
		height:100vh;
	}
</style>